//
//  PriceDetailController.swift
//  SwiftStudy
//
//  Created by mybox_1027@sina.com on 16/4/6.
//  Copyright © 2016年 mybox_1027@sina.com. All rights reserved.
//

import Foundation

class PriceDetailController: UITableViewController {
    
    let kPaySupplierDetailCellStartIndex = 1
    
    enum EnumPriceDetailCell:String {
        case PayMethodCell = "PayMethodCell"
        case PaySupplierDetailCell = "PaySupplierDetailCell"
        case CouponValueCell = "CouponValueCell"
        case PriceTotalCell = "PriceTotalCell"
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.tableView.reloadData()
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.supplierCount() + 3
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let row = indexPath.row
        
        if self.isSupplierDetailCell(row)
        {
            let cell = tableView.dequeueReusableCellWithIdentifier(EnumPriceDetailCell.PaySupplierDetailCell.rawValue) as! PaySupplierDetailCell
            cell.supplierImage.image = UIImage.init(named: "ota_AirAsia")
            return cell
        }
        else
        {
            if row == EnumPriceDetailCell.PayMethodCell.hashValue {
                let cell = tableView.dequeueReusableCellWithIdentifier(EnumPriceDetailCell.PayMethodCell.rawValue) as! PayMethodCell
                cell.payMethodImage.image = UIImage.init(named: "follow_wechat")
                return cell
            }
            else if row == (self.supplierCount() + 1)
            {
                let cell = tableView.dequeueReusableCellWithIdentifier(EnumPriceDetailCell.CouponValueCell.rawValue) as! CouponValueCell
                return cell
            }
            else if row == (self.supplierCount() + 2)
            {
                let cell = tableView.dequeueReusableCellWithIdentifier(EnumPriceDetailCell.PriceTotalCell.rawValue) as! PriceTotalCell
                return cell
            }
        }
        
        let cell:UITableViewCell! = nil
        return cell
}
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        if isSupplierDetailCell(indexPath.row) {
            return 180
        }
        return 60
    }
    
    func initData(priceDetail:Dictionary<String,String>){
        //init 
    }
    
    private func isSupplierDetailCell(row:Int) ->Bool
    {
        var isSupplier = false;
        
        if (kPaySupplierDetailCellStartIndex<=row)&&(row<self.supplierCount()+kPaySupplierDetailCellStartIndex) {
            isSupplier = true
        }
        
        return isSupplier
    }
    
    private func supplierCount()->Int
    {
        let supplierList:NSMutableArray? = nil
        
        if supplierList != nil {
            return supplierList!.count
        }
        return 2//0
    }
}